package dto

import (
	"github.com/gin-gonic/gin/binding"
	"github.com/go-playground/validator/v10"
	"mall-go/util"
)

//初始化
func init() {
	if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
		//注册校验(忽略错误)
		_ = v.RegisterValidation("checkRank", util.CheckRank)
		_ = v.RegisterValidation("checkLevel", util.CheckLevel)
		_ = v.RegisterValidation("maxLen", util.MaxLen)
		_ = v.RegisterValidation("minLen", util.MinLen)
		_ = v.RegisterValidation("max", util.Max)
		_ = v.RegisterValidation("min", util.Min)
	}
}

// LoginParam 登录时的入参
type LoginParam struct {
	UserName string `json:"userName" binding:"required"`
	Password string `json:"passwordMd5" binding:"required"`
}

// UpdatePasswordParam 修改密码时入参
type UpdatePasswordParam struct {
	OriginalPassword string `json:"originalPassword" binding:"required"`
	NewPassword      string `json:"newPassword" binding:"required"`
}

// UpdateNameParam 修改用户名的入参
type UpdateNameParam struct {
	LoginUserName string `json:"loginUserName" binding:"required"`
	NickName      string `json:"nickName" binding:"required"`
}

// BatchIdParam 用户id集合
type BatchIdParam struct {
	UserIds []int `json:"ids"`
}

// CarouselAddParam 轮播图添加
type CarouselAddParam struct {
	CarouselUrl  string `json:"carouselUrl" binding:"required"`
	RedirectUrl  string `json:"redirectURl" binding:"required"`
	CarouselRank string `json:"carouselRank" binding:"required,checkRank"`
}

// CarouselUpdateParam 轮播图修改
type CarouselUpdateParam struct {
	CarouselId   int    `json:"carouselId" binding:"required"`
	CarouselUrl  string `json:"carouselUrl" binding:"required"`
	RedirectUrl  string `json:"redirectURl" binding:"required"`
	CarouselRank string `json:"carouselRank" binding:"required,checkRank"`
}

// GoodsCategoryAddParam 商品分类添加
type GoodsCategoryAddParam struct {
	CategoryLevel int    `json:"categoryLevel" binding:"required,checkLevel"`
	ParentId      *int   `json:"parentId" binding:"required"`
	CategoryName  string `json:"categoryName" binding:"required,maxLen=16"`
	CategoryRank  string `json:"categoryRank" binding:"required,checkRank"`
}

// GoodsCategoryEditParam 商品分类更新
type GoodsCategoryEditParam struct {
	CategoryId    int    `json:"categoryId" binding:"required"`
	CategoryLevel int    `json:"categoryLevel" binding:"required,checkLevel"`
	ParentId      *int   `json:"parentId" binding:"required"`
	CategoryName  string `json:"categoryName" binding:"required,maxLen=16"`
	CategoryRank  int    `json:"categoryRank" binding:"required,checkRank"`
}

// GoodsAddParam 商品添加
type GoodsAddParam struct {
	GoodsName          string `json:"goodsName" binding:"required,maxLen=128"`
	GoodsIntro         string `json:"goodsIntro" binding:"required,maxLen=200"`
	GoodsCategoryId    *int   `json:"goodsCategoryId" binding:"required,min=1"`
	GoodsCoverImg      string `json:"goodsCoverImg" binding:"required"`
	OriginalPrice      string `json:"originalPrice" binding:"required,min=1,max=1000000"`
	SellingPrice       string `json:"sellingPrice" binding:"required,min=1,max=1000000"`
	StockNum           string `json:"stockNum" binding:"required,min=1,max=1000000"`
	Tag                string `json:"tag" binding:"required,maxLen=16"`
	GoodsSellStatus    string `json:"goodsSellStatus"`
	GoodsDetailContent string `json:"goodsDetailContent" binding:"required"`
}

// GoodsEditParam 商品更新
type GoodsEditParam struct {
	GoodsId            string `json:"goodsId" binding:"required,min=1"`
	GoodsName          string `json:"goodsName" binding:"required,maxLen=128"`
	GoodsIntro         string `json:"goodsIntro" binding:"required,maxLen=200"`
	GoodsCategoryId    *int   `json:"goodsCategoryId" binding:"required,min=1"`
	GoodsCoverImg      string `json:"goodsCoverImg" binding:"required"`
	OriginalPrice      int    `json:"originalPrice" binding:"required,min=1,max=1000000"`
	SellingPrice       int    `json:"sellingPrice" binding:"required,min=1,max=1000000"`
	StockNum           int    `json:"stockNum" binding:"required,min=1,max=1000000"`
	Tag                string `json:"tag" binding:"required,maxLen=16"`
	GoodsSellStatus    string `json:"goodsSellStatus"`
	GoodsDetailContent string `json:"goodsDetailContent" binding:"required"`
}

//IndexConfigAddParam 首页添加
type IndexConfigAddParam struct {
	ConfigName string `json:"configName" binding:"required"`
	ConfigType int    `json:"configType" binding:"required,min=1,max=5"`
	GoodsId    string `json:"goodsId" binding:"required,min=1"`
	ConfigRank string `json:"configRank" binding:"required,checkRank"`
}

// IndexConfigEditParam 首页修改
type IndexConfigEditParam struct {
	ConfigId   int    `json:"configId" binding:"required,min=1"`
	ConfigName string `json:"configName" binding:"required"`
	ConfigType int    `json:"configType" binding:"required,min=1,max=5"`
	GoodsId    int    `json:"goodsId" binding:"required,min=1"`
	ConfigRank int    `json:"configRank" binding:"required,checkRank"`
}
